home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-18 | 1.9 KB | 82 lines | [TEXT/CWIE] |
- // SecureGWorld.cp, the SecureGWorld class, useful for generating GWorlds
- // for those who do not use a framework to make GWorlds for them.
-
- // copyright © 1995, Macneil Shonle. All rights reserved.
-
- #ifndef __SECUREGWORLD__
- #include <SecureGWorld.h>
- #endif
-
- #ifndef __GWORLDSETTER__
- #include <GWorldSetter.h>
- #endif
-
- // constructs the GWorld from the parameters
- // may throw: xalloc, invalidargument
- SecureGWorld::SecureGWorld(const Rect &bounds, BitDepth depth, CTabHandle ctab)
- throw(xalloc, invalidargument)
- {
- QDErr err = ::NewGWorld(&gworld, depth, &bounds, ctab, nil, 0);
-
- if (err == noErr) {
- GWorldSetter setTo(gworld);
-
- ::LockPixels(::GetGWorldPixMap(gworld));
- ::ClipRect(&gworld->portRect);
- ::EraseRect(&gworld->portRect);
- }
- else if (err == paramErr)
- throw invalidargument("NewGWorld paramErr", "SecureGWorld::SecureGWorld");
- else if (err == cDepthErr)
- throw invalidargument("NewGWorld cDepthErr", "SecureGWorld::SecureGWorld");
- else
- throw xalloc("NewGWorld failed", "SecureGWorld::SecureGWorld");
- }
-
- // disposes the GWorld
- SecureGWorld::~SecureGWorld()
- {
- ::DisposeGWorld(gworld);
- }
-
- // returns the GWorld's port-rectangle
- Rect& SecureGWorld::portRect() const
- {
- return gworld->portRect;
- }
-
- // returns a pointer to the GWorld's bit-map
- BitMapPtr SecureGWorld::bitMap() const
- {
- return &GrafPtr(gworld)->portBits;
- }
-
- // returns the GWorld's width
- short SecureGWorld::width() const
- {
- return gworld->portRect.right - gworld->portRect.left;
- }
-
- // returns the GWorld's height
- short SecureGWorld::height() const
- {
- return gworld->portRect.bottom - gworld->portRect.top;
- }
-
- // returns the GWorld as a CGrafPtr
- CGrafPtr SecureGWorld::getMacPort() const
- {
- return CGrafPtr(gworld);
- }
-
- // returns the graphics device of the GWorld
- GDHandle SecureGWorld::getMacGD() const
- {
- return nil;
- }
-
- // "returns" the GWorldPtr
- SecureGWorld::operator GWorldPtr() const
- {
- return gworld;
- }